import { PageConfig } from 'next';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an48 from '@mmstudio/an000048';
import { tbjob, tbs_job_ment } from '../../../../atoms/db';

const logger = anylogger('pages/api/zllweapp/feedback/s001.api');

export type Result = {
	ok: true;
	s_jobcontent: Pick<ITbjob, 's_jobcontext' | 'mark' | 'teacherscomments'>
	s_jobcontent_at: Pick<ITbs_job_ment, 's_picture'>
} | {
	ok: false;
	message: string;
};

export type Message = {
	id: string;
}

/**
 * pages/api/zllweapp/feedback/s001.api
 */
const handler = an48<Result>();

handler.post(async (req, res) => {
	try {
		logger.debug('msg body:', req.body);
		const { id } = req.body as Message;
		//**后期获取学生id */
		const student_id = '201942908581';

		//**学生提交作业内容,老师评语和评级----从学生作业表进行查询 /
		const s_jobcontent = await tbjob().first('s_jobcontext', 'mark', 'teacherscomments').where({
			job_id: id,
			student_id: student_id
		});
		//**学生提交作业内容----从学生作业附件表进行查询 /
		const s_jobcontent_at = await tbs_job_ment().first('s_picture').where({
			job_id: id,
			student_id: student_id
		});


		res.status(200).json({ ok: true, s_jobcontent, s_jobcontent_at });
	} catch (error) {
		logger.trace(error);
		res.status(200).json({ ok: false, message: (error as Error).message });
	}
});

export const config = {} as PageConfig;

export default handler;
